package com.linkoog.devtools.utils;

import java.util.concurrent.atomic.AtomicInteger;

public class CricleNumber {
    private final AtomicInteger index = new AtomicInteger(1);
    private final boolean fillZero;
    private final int max;


    public CricleNumber( int max, boolean fillZero) {
        this.max = max;
        this.fillZero = fillZero;
    }

    public String nextNum(){
        String result;
        final int i = index.get();
        if (i < 10){
            result =  fillZero? "0" + i : String.valueOf(i);
        } else {
            result = String.valueOf(i);
        }

        if (index.get() == max ){
            index.compareAndExchange(max,1);
        } else {
            index.incrementAndGet();
        }

        return result;
    }
}
